﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vowei.Service;
using System.Web;

namespace vowei.Web.Helpers
{
    public class TicketServiceContext : IServiceHttpContext
    {
        public string ApplicationPath
        {
            get { return HttpContext.Current.Request.ApplicationPath; }
        }

        private IServiceHttpCache _cache = new ServiceHttpCache();
        public IServiceHttpCache Cache
        {
            get { return _cache; }
        }
    }

    public class ServiceHttpCache : IServiceHttpCache
    {
        public int Count
        {
            get { return HttpContext.Current.Cache.Count; }
        }

        public long EffectivePercentagePhysicalMemoryLimit
        {
            get { return HttpContext.Current.Cache.EffectivePercentagePhysicalMemoryLimit; }
        }

        public long EffectivePrivateBytesLimit
        {
            get { return HttpContext.Current.Cache.EffectivePrivateBytesLimit; }
        }

        public object this[string key]
        {
            get
            {
                return HttpContext.Current.Cache[key];
            }
            set
            {
                HttpContext.Current.Cache[key] = value;
            }
        }

        public object Add(string key, object value, System.Web.Caching.CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, System.Web.Caching.CacheItemPriority priority, System.Web.Caching.CacheItemRemovedCallback onRemoveCallback)
        {
            return HttpContext.Current.Cache.Add(key, value, dependencies, absoluteExpiration, slidingExpiration, priority, onRemoveCallback);
        }

        public object Get(string key)
        {
            return HttpContext.Current.Cache.Get(key);
        }

        public void Insert(string key, object value)
        {
            HttpContext.Current.Cache.Insert(key, value);
        }

        public void Insert(string key, object value, System.Web.Caching.CacheDependency dependencies, DateTime absoluteExpiration, TimeSpan slidingExpiration, System.Web.Caching.CacheItemPriority priority, System.Web.Caching.CacheItemRemovedCallback onRemoveCallback)
        {
            HttpContext.Current.Cache.Insert(key, value, dependencies, absoluteExpiration, slidingExpiration);
        }

        public object Remove(string key)
        {
            return HttpContext.Current.Cache.Remove(key);
        }
    }

}
